package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.ExpertNewVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hedgehog.ratingbar.RatingBar;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.text.MessageFormat;


/**
 * 专家咨询
 */
public class ExpertConsultationHolder extends BaseViewHolder<ExpertNewVO> {

    private SimpleDraweeView ivImage;//头像

    private TextView tvExpertName;//姓名
    private TextView tvExpertTitle;//职称
    private TextView tvExpertArea;//涉及领域
    private RatingBar barScore;//评分
    private TextView tvAskNum;  // 提问量
    private TextView tvReplyNum; // 回复量
    private TextView tvStudentNum; // 学员数
    private TextView address; // 地址
    private TextView tvFree; // 是否付费


    public ExpertConsultationHolder(ViewGroup parent) {
        super(parent, R.layout.item_expert_consultation);
        ivImage = $(R.id.item_iv_expert_iv_avatar);
        tvExpertName = $(R.id.item_expert_list_tv_name);
        tvExpertTitle = $(R.id.item_expert_list_tv_titles);
        tvExpertArea = $(R.id.item_expert_list_tv_area);
        barScore = $(R.id.item_expert_list_bar_score);

        tvAskNum = $(R.id.item_expert_list_tv_ask_num);
        tvReplyNum = $(R.id.item_expert_list_tv_reply_num);
        tvStudentNum = $(R.id.item_expert_list_tv_student_num);
        address = $(R.id.address);
        tvFree = $(R.id.tv_free);
    }

    @Override
    public void setData(final ExpertNewVO data) {
        super.setData(data);

        //咨询是否收费 0-免费 1-收费
        if ("1".equals(data.getConsultIsFee())) {
            tvFree.setText(data.getConsultFee() + "元/次 问专家");
        } else {
            tvFree.setText("免费问专家");
        }

        tvExpertName.setText(!StringUtil.isStrEmpty(data.getExpertName()) ? data.getExpertName() : "匿名专家");

        tvAskNum.setText(MessageFormat.format("提问量：{0}", StringUtil.isStrEmpty(data.getQuestionNUm()) ? "0" : data.getQuestionNUm()));
        tvReplyNum.setText(MessageFormat.format("回复量：{0}", StringUtil.isStrEmpty(data.getAnswerNum()) ? "0" : data.getAnswerNum()));
        tvStudentNum.setText(MessageFormat.format("学员数：{0}", StringUtil.isStrEmpty(data.getStudentNum()) ? "0" : data.getStudentNum()));
        address.setText((data.getProvince() == null ? "" : data.getProvince().getName()) + (data.getCity() == null ? "" : data.getCity().getName())
                + (data.getCounty() == null ? "" : data.getCounty().getName()));

        FrescoUtil.showImageSmall(data.getPhoto(), ivImage);


        if (data.getExpertTitle() == null || StringUtil.isStrEmpty(data.getExpertTitle().getTitle())) {
            tvExpertTitle.setVisibility(View.GONE);
        } else {
            tvExpertTitle.setVisibility(View.VISIBLE);
            tvExpertTitle.setText(data.getExpertTitle().getTitle());
        }

        if (data.getExpertAreas() != null) {
            String s = "";
            for (int i = 0; i < data.getExpertAreas().size(); i++) {
                s += data.getExpertAreas().get(i).getExpertAreaType().getName() + "-"
                        + data.getExpertAreas().get(i).getExpertAreaDirection().getName() + "  ";
            }
            tvExpertArea.setText(s);
        }
        barScore.setStar((float) data.getScore());

//        tvExpertArea.setText(data.getExpertClassification() != null ? data.getExpertClassification().getPname() + "  " + data.getExpertClassification().getName() : "");

//        if (!TextUtils.isEmpty(data.getExpertSex())) {
//            if (data.getExpertSex().equals("男")) {
//                isMale();
//            } else {
//                isFemale();
//            }
//        }
    }

}
